package approvalDaoImplement;

import approvalDao.Information;
import approvalDao.ViewUsers;
import com.alibaba.fastjson.JSON;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
/**
 * \* Created with IntelliJ IDEA.
 * \* User: LYZ
 * \* Date: 2022/2/19
 * \* Time: 17:29
 * \* Description:   显示所有待审批的借书申请
 * \
 */

@WebServlet(name = "ViewUsersServlet", value = "/ViewUsersServlet")
public class ViewUsersServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 响应参数格式设置
        //response.setCharacterEncoding("UTF-8");
        //response.setContentType("text/html;charset=UTF-
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        //将此字符串对象输出
        PrintWriter out = response.getWriter();
        ViewUsers viewUsers = new ViewUsers();
        List<Information> information = null;
        //将待审批记录存入集合
        try {
            information = viewUsers.viewList();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        String str = JSON.toJSONString(information);

        //将信息返回前端页面
        out.println(str);



    }
}
